home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 85 / CD-ROM 85 / CD-ROM 85.iso / med2000 / eventos / ASTRO.JS < prev    next >
Encoding:
JavaScript  |  2000-12-30  |  23.0 KB  |  626 lines

  1. /*
  2.             JavaScript functions for positional astronomy
  3.  
  4.                   by John Walker  --  September, MIM
  5.                        http://www.fourmilab.ch/
  6.  
  7.                 This program is in the public domain.
  8. */
  9.  
  10. //  Frequently-used constants
  11.  
  12. var
  13.     J2000             = 2451545.0,              // Julian day of J2000 epoch
  14.     JulianCentury     = 36525.0,                // Days in Julian century
  15.     JulianMillennium  = (JulianCentury * 10),   // Days in Julian millennium
  16.     AstronomicalUnit  = 149597870.0,            // Astronomical unit in kilometres
  17.     TropicalYear      = 365.24219878;           // Mean solar tropical year
  18.  
  19. /*  ASTOR  --  Arc-seconds to radians.  */
  20.  
  21. function astor(a)
  22. {
  23.     return a * (Math.PI / (180.0 * 3600.0));
  24. }
  25.  
  26. /*  DTR  --  Degrees to radians.  */
  27.  
  28. function dtr(d)
  29. {
  30.     return (d * Math.PI) / 180.0;
  31. }
  32.  
  33. /*  RTD  --  Radians to degrees.  */
  34.  
  35. function rtd(r)
  36. {
  37.     return (r * 180.0) / Math.PI;
  38. }
  39.  
  40. /*  FIXANGLE  --  Range reduce angle in degrees.  */
  41.  
  42. function fixangle(a)
  43. {
  44.         return a - 360.0 * (Math.floor(a / 360.0));
  45. }
  46.  
  47. /*  FIXANGR  --  Range reduce angle in radians.  */
  48.  
  49. function fixangr(a)
  50. {
  51.         return a - (2 * Math.PI) * (Math.floor(a / (2 * Math.PI)));
  52. }
  53.  
  54. //  DSIN  --  Sine of an angle in degrees
  55.  
  56. function dsin(d)
  57. {
  58.     return Math.sin(dtr(d));
  59. }
  60.  
  61. //  DCOS  --  Cosine of an angle in degrees
  62.  
  63. function dcos(d)
  64. {
  65.     return Math.cos(dtr(d));
  66. }
  67.  
  68. /*  MOD  --  Modulus function which works for non-integers.  */
  69.  
  70. function mod(a, b)
  71. {
  72.     return a - (b * Math.floor(a / b));
  73. }
  74.  
  75. //  AMOD  --  Modulus function which returns numerator if modulus is zero
  76.  
  77. function amod(a, b)
  78. {
  79.     return mod(a - 1, b) + 1;
  80. }
  81.  
  82. /*  JHMS  --  Convert Julian time to hour, minutes, and seconds,
  83.               returned as a three-element array.  */
  84.  
  85. function jhms(j) {
  86.     var ij;
  87.  
  88.     j += 0.5;                 /* Astronomical to civil */
  89.     ij = (j - Math.floor(j)) * 86400.0;
  90.     return new Array(
  91.                      Math.floor(ij / 3600),
  92.                      Math.floor((ij / 60) % 60),
  93.                      Math.floor(ij % 60));
  94. }
  95.  
  96. //  JWDAY  --  Calculate day of week from Julian day
  97.  
  98. var Weekdays = new Array( "Domingo", "Segunda", "Terτa", "Quarta",
  99.                           "Quinta", "Sexta", "Sßbado" );
  100.  
  101. function jwday(j)
  102. {
  103.     return mod(Math.floor((j + 1.5)), 7);
  104. }
  105.  
  106. /*  OBLIQEQ  --  Calculate the obliquity of the ecliptic for a given
  107.                  Julian date.  This uses Laskar's tenth-degree
  108.                  polynomial fit (J. Laskar, Astronomy and
  109.                  Astrophysics, Vol. 157, page 68 [1986]) which is
  110.                  accurate to within 0.01 arc second between AD 1000
  111.                  and AD 3000, and within a few seconds of arc for
  112.                  +/-10000 years around AD 2000.  If we're outside the
  113.                  range in which this fit is valid (deep time) we
  114.                  simply return the J2000 value of the obliquity, which
  115.                  happens to be almost precisely the mean.  */
  116.  
  117. var oterms = new Array (
  118.         -4680.93,
  119.            -1.55,
  120.          1999.25,
  121.           -51.38,
  122.          -249.67,
  123.           -39.05,
  124.             7.12,
  125.            27.87,
  126.             5.79,
  127.             2.45
  128. );
  129.  
  130. function obliqeq(jd)
  131. {
  132.     var eps, u, v, i;
  133.  
  134.     v = u = (jd - J2000) / (JulianCentury * 100);
  135.  
  136.     eps = 23 + (26 / 60.0) + (21.448 / 3600.0);
  137.  
  138.     if (Math.abs(u) < 1.0) {
  139.         for (i = 0; i < 10; i++) {
  140.             eps += (oterms[i] / 3600.0) * v;
  141.             v *= u;
  142.         }
  143.     }
  144.     return eps;
  145. }
  146.  
  147. /* Periodic terms for nutation in longiude (delta \Psi) and
  148.    obliquity (delta \Epsilon) as given in table 21.A of
  149.    Meeus, "Astronomical Algorithms", first edition. */
  150.  
  151. var nutArgMult = new Array(
  152.      0,  0,  0,  0,  1,
  153.     -2,  0,  0,  2,  2,
  154.      0,  0,  0,  2,  2,
  155.      0,  0,  0,  0,  2,
  156.      0,  1,  0,  0,  0,
  157.      0,  0,  1,  0,  0,
  158.     -2,  1,  0,  2,  2,
  159.      0,  0,  0,  2,  1,
  160.      0,  0,  1,  2,  2,
  161.     -2, -1,  0,  2,  2,
  162.     -2,  0,  1,  0,  0,
  163.     -2,  0,  0,  2,  1,
  164.      0,  0, -1,  2,  2,
  165.      2,  0,  0,  0,  0,
  166.      0,  0,  1,  0,  1,
  167.      2,  0, -1,  2,  2,
  168.      0,  0, -1,  0,  1,
  169.      0,  0,  1,  2,  1,
  170.     -2,  0,  2,  0,  0,
  171.      0,  0, -2,  2,  1,
  172.      2,  0,  0,  2,  2,
  173.      0,  0,  2,  2,  2,
  174.      0,  0,  2,  0,  0,
  175.     -2,  0,  1,  2,  2,
  176.      0,  0,  0,  2,  0,
  177.     -2,  0,  0,  2,  0,
  178.      0,  0, -1,  2,  1,
  179.      0,  2,  0,  0,  0,
  180.      2,  0, -1,  0,  1,
  181.     -2,  2,  0,  2,  2,
  182.      0,  1,  0,  0,  1,
  183.     -2,  0,  1,  0,  1,
  184.      0, -1,  0,  0,  1,
  185.      0,  0,  2, -2,  0,
  186.      2,  0, -1,  2,  1,
  187.      2,  0,  1,  2,  2,
  188.      0,  1,  0,  2,  2,
  189.     -2,  1,  1,  0,  0,
  190.      0, -1,  0,  2,  2,
  191.      2,  0,  0,  2,  1,
  192.      2,  0,  1,  0,  0,
  193.     -2,  0,  2,  2,  2,
  194.     -2,  0,  1,  2,  1,
  195.      2,  0, -2,  0,  1,
  196.      2,  0,  0,  0,  1,
  197.      0, -1,  1,  0,  0,
  198.     -2, -1,  0,  2,  1,
  199.     -2,  0,  0,  0,  1,
  200.      0,  0,  2,  2,  1,
  201.     -2,  0,  2,  0,  1,
  202.     -2,  1,  0,  2,  1,
  203.      0,  0,  1, -2,  0,
  204.     -1,  0,  1,  0,  0,
  205.     -2,  1,  0,  0,  0,
  206.      1,  0,  0,  0,  0,
  207.      0,  0,  1,  2,  0,
  208.     -1, -1,  1,  0,  0,
  209.      0,  1,  1,  0,  0,
  210.      0, -1,  1,  2,  2,
  211.      2, -1, -1,  2,  2,
  212.      0,  0, -2,  2,  2,
  213.      0,  0,  3,  2,  2,
  214.      2, -1,  0,  2,  2
  215. );
  216.  
  217. var nutArgCoeff = new Array(
  218.     -171996,   -1742,   92095,      89,          /*  0,  0,  0,  0,  1 */
  219.      -13187,     -16,    5736,     -31,          /* -2,  0,  0,  2,  2 */
  220.       -2274,      -2,     977,      -5,          /*  0,  0,  0,  2,  2 */
  221.        2062,       2,    -895,       5,          /*  0,  0,  0,  0,  2 */
  222.        1426,     -34,      54,      -1,          /*  0,  1,  0,  0,  0 */
  223.         712,       1,      -7,       0,          /*  0,  0,  1,  0,  0 */
  224.        -517,      12,     224,      -6,          /* -2,  1,  0,  2,  2 */
  225.        -386,      -4,     200,       0,          /*  0,  0,  0,  2,  1 */
  226.        -301,       0,     129,      -1,          /*  0,  0,  1,  2,  2 */
  227.         217,      -5,     -95,       3,          /* -2, -1,  0,  2,  2 */
  228.        -158,       0,       0,       0,          /* -2,  0,  1,  0,  0 */
  229.         129,       1,     -70,       0,          /* -2,  0,  0,  2,  1 */
  230.         123,       0,     -53,       0,          /*  0,  0, -1,  2,  2 */
  231.          63,       0,       0,       0,          /*  2,  0,  0,  0,  0 */
  232.          63,       1,     -33,       0,          /*  0,  0,  1,  0,  1 */
  233.         -59,       0,      26,       0,          /*  2,  0, -1,  2,  2 */
  234.         -58,      -1,      32,       0,          /*  0,  0, -1,  0,  1 */
  235.         -51,       0,      27,       0,          /*  0,  0,  1,  2,  1 */
  236.          48,       0,       0,       0,          /* -2,  0,  2,  0,  0 */
  237.          46,       0,     -24,       0,          /*  0,  0, -2,  2,  1 */
  238.         -38,       0,      16,       0,          /*  2,  0,  0,  2,  2 */
  239.         -31,       0,      13,       0,          /*  0,  0,  2,  2,  2 */
  240.          29,       0,       0,       0,          /*  0,  0,  2,  0,  0 */
  241.          29,       0,     -12,       0,          /* -2,  0,  1,  2,  2 */
  242.          26,       0,       0,       0,          /*  0,  0,  0,  2,  0 */
  243.         -22,       0,       0,       0,          /* -2,  0,  0,  2,  0 */
  244.          21,       0,     -10,       0,          /*  0,  0, -1,  2,  1 */
  245.          17,      -1,       0,       0,          /*  0,  2,  0,  0,  0 */
  246.          16,       0,      -8,       0,          /*  2,  0, -1,  0,  1 */
  247.         -16,       1,       7,       0,          /* -2,  2,  0,  2,  2 */
  248.         -15,       0,       9,       0,          /*  0,  1,  0,  0,  1 */
  249.         -13,       0,       7,       0,          /* -2,  0,  1,  0,  1 */
  250.         -12,       0,       6,       0,          /*  0, -1,  0,  0,  1 */
  251.          11,       0,       0,       0,          /*  0,  0,  2, -2,  0 */
  252.         -10,       0,       5,       0,          /*  2,  0, -1,  2,  1 */
  253.          -8,       0,       3,       0,          /*  2,  0,  1,  2,  2 */
  254.           7,       0,      -3,       0,          /*  0,  1,  0,  2,  2 */
  255.          -7,       0,       0,       0,          /* -2,  1,  1,  0,  0 */
  256.          -7,       0,       3,       0,          /*  0, -1,  0,  2,  2 */
  257.          -7,       0,       3,       0,          /*  2,  0,  0,  2,  1 */
  258.           6,       0,       0,       0,          /*  2,  0,  1,  0,  0 */
  259.           6,       0,      -3,       0,          /* -2,  0,  2,  2,  2 */
  260.           6,       0,      -3,       0,          /* -2,  0,  1,  2,  1 */
  261.          -6,       0,       3,       0,          /*  2,  0, -2,  0,  1 */
  262.          -6,       0,       3,       0,          /*  2,  0,  0,  0,  1 */
  263.           5,       0,       0,       0,          /*  0, -1,  1,  0,  0 */
  264.          -5,       0,       3,       0,          /* -2, -1,  0,  2,  1 */
  265.          -5,       0,       3,       0,          /* -2,  0,  0,  0,  1 */
  266.          -5,       0,       3,       0,          /*  0,  0,  2,  2,  1 */
  267.           4,       0,       0,       0,          /* -2,  0,  2,  0,  1 */
  268.           4,       0,       0,       0,          /* -2,  1,  0,  2,  1 */
  269.           4,       0,       0,       0,          /*  0,  0,  1, -2,  0 */
  270.          -4,       0,       0,       0,          /* -1,  0,  1,  0,  0 */
  271.          -4,       0,       0,       0,          /* -2,  1,  0,  0,  0 */
  272.          -4,       0,       0,       0,          /*  1,  0,  0,  0,  0 */
  273.           3,       0,       0,       0,          /*  0,  0,  1,  2,  0 */
  274.          -3,       0,       0,       0,          /* -1, -1,  1,  0,  0 */
  275.          -3,       0,       0,       0,          /*  0,  1,  1,  0,  0 */
  276.          -3,       0,       0,       0,          /*  0, -1,  1,  2,  2 */
  277.          -3,       0,       0,       0,          /*  2, -1, -1,  2,  2 */
  278.          -3,       0,       0,       0,          /*  0,  0, -2,  2,  2 */
  279.          -3,       0,       0,       0,          /*  0,  0,  3,  2,  2 */
  280.          -3,       0,       0,       0           /*  2, -1,  0,  2,  2 */
  281. );
  282.  
  283. /*  NUTATION  --  Calculate the nutation in longitude, deltaPsi, and
  284.                   obliquity, deltaEpsilon for a given Julian date
  285.                   jd.  Results are returned as a two element Array
  286.                   giving (deltaPsi, deltaEpsilon) in degrees.  */
  287.  
  288. function nutation(jd)
  289. {
  290.     var deltaPsi, deltaEpsilon,
  291.         i, j,
  292.         t = (jd - 2451545.0) / 36525.0, t2, t3, to10,
  293.         ta = new Array,
  294.         dp = 0, de = 0, ang;
  295.  
  296.     t3 = t * (t2 = t * t);
  297.  
  298.     /* Calculate angles.  The correspondence between the elements
  299.        of our array and the terms cited in Meeus are:
  300.  
  301.        ta[0] = D  ta[0] = M  ta[2] = M'  ta[3] = F  ta[4] = \Omega
  302.  
  303.     */
  304.  
  305.     ta[0] = dtr(297.850363 + 445267.11148 * t - 0.0019142 * t2 + 
  306.                 t3 / 189474.0);
  307.     ta[1] = dtr(357.52772 + 35999.05034 * t - 0.0001603 * t2 -
  308.                 t3 / 300000.0);
  309.     ta[2] = dtr(134.96298 + 477198.867398 * t + 0.0086972 * t2 +
  310.                 t3 / 56250.0);
  311.     ta[3] = dtr(93.27191 + 483202.017538 * t - 0.0036825 * t2 +
  312.                 t3 / 327270);
  313.     ta[4] = dtr(125.04452 - 1934.136261 * t + 0.0020708 * t2 +
  314.                 t3 / 450000.0);
  315.  
  316.     /* Range reduce the angles in case the sine and cosine functions
  317.        don't do it as accurately or quickly. */
  318.  
  319.     for (i = 0; i < 5; i++) {
  320.         ta[i] = fixangr(ta[i]);
  321.     }
  322.  
  323.     to10 = t / 10.0;
  324.     for (i = 0; i < 63; i++) {
  325.         ang = 0;
  326.         for (j = 0; j < 5; j++) {
  327.             if (nutArgMult[(i * 5) + j] != 0) {
  328.                 ang += nutArgMult[(i * 5) + j] * ta[j];
  329.             }
  330.         }
  331.         dp += (nutArgCoeff[(i * 4) + 0] + nutArgCoeff[(i * 4) + 1] * to10) * Math.sin(ang);
  332.         de += (nutArgCoeff[(i * 4) + 2] + nutArgCoeff[(i * 4) + 3] * to10) * Math.cos(ang);
  333.     }
  334.  
  335.     /* Return the result, converting from ten thousandths of arc
  336.        seconds to radians in the process. */
  337.  
  338.     deltaPsi = dp / (3600.0 * 10000.0);
  339.     deltaEpsilon = de / (3600.0 * 10000.0);
  340.  
  341.     return new Array(deltaPsi, deltaEpsilon);
  342. }
  343.  
  344. /*  ECLIPTOEQ  --  Convert celestial (ecliptical) longitude and
  345.                    latitude into right ascension (in degrees) and
  346.                    declination.  We must supply the time of the
  347.                    conversion in order to compensate correctly for the
  348.                    varying obliquity of the ecliptic over time.
  349.                    The right ascension and declination are returned
  350.                    as a two-element Array in that order.  */
  351.  
  352. function ecliptoeq(jd, Lambda, Beta)
  353. {
  354.     var eps, Ra, Dec;
  355.  
  356.     /* Obliquity of the ecliptic. */
  357.  
  358.     eps = dtr(obliqeq(jd));
  359. log += "Obliquity: " + rtd(eps) + "\n";
  360.  
  361.     Ra = rtd(Math.atan2((Math.cos(eps) * Math.sin(dtr(Lambda)) -
  362.                         (Math.tan(dtr(Beta)) * Math.sin(eps))),
  363.                       Math.cos(dtr(Lambda))));
  364. log += "RA = " + Ra + "\n";
  365.     Ra = fixangle(rtd(Math.atan2((Math.cos(eps) * Math.sin(dtr(Lambda)) -
  366.                         (Math.tan(dtr(Beta)) * Math.sin(eps))),
  367.                       Math.cos(dtr(Lambda)))));
  368.     Dec = rtd(Math.asin((Math.sin(eps) * Math.sin(dtr(Lambda)) * Math.cos(dtr(Beta))) +
  369.                  (Math.sin(dtr(Beta)) * Math.cos(eps))));
  370.  
  371.     return new Array(Ra, Dec);
  372. }
  373.  
  374.  
  375. /*  DELTAT  --  Determine the difference, in seconds, between
  376.                 Dynamical time and Universal time.  */
  377.  
  378. /*  Table of observed Delta T values at the beginning of
  379.     even numbered years from 1620 through 2002.  */
  380.  
  381. var deltaTtab = new Array(
  382.     121, 112, 103, 95, 88, 82, 77, 72, 68, 63, 60, 56, 53, 51, 48, 46,
  383.     44, 42, 40, 38, 35, 33, 31, 29, 26, 24, 22, 20, 18, 16, 14, 12,
  384.     11, 10, 9, 8, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10,
  385.     10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13,
  386.     13, 14, 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
  387.     16, 16, 15, 15, 14, 13, 13.1, 12.5, 12.2, 12, 12, 12, 12, 12, 12,
  388.     11.9, 11.6, 11, 10.2, 9.2, 8.2, 7.1, 6.2, 5.6, 5.4, 5.3, 5.4, 5.6,
  389.     5.9, 6.2, 6.5, 6.8, 7.1, 7.3, 7.5, 7.6, 7.7, 7.3, 6.2, 5.2, 2.7,
  390.     1.4, -1.2, -2.8, -3.8, -4.8, -5.5, -5.3, -5.6, -5.7, -5.9, -6,
  391.     -6.3, -6.5, -6.2, -4.7, -2.8, -0.1, 2.6, 5.3, 7.7, 10.4, 13.3, 16,
  392.     18.2, 20.2, 21.1, 22.4, 23.5, 23.8, 24.3, 24, 23.9, 23.9, 23.7,
  393.     24, 24.3, 25.3, 26.2, 27.3, 28.2, 29.1, 30, 30.7, 31.4, 32.2,
  394.     33.1, 34, 35, 36.5, 38.3, 40.2, 42.2, 44.5, 46.5, 48.5, 50.5,
  395.     52.2, 53.8, 54.9, 55.8, 56.9, 58.3, 60, 61.6, 63, 65, 66.6
  396.                          );
  397.  
  398. function deltat(year)
  399. {
  400.     var dt, f, i, t;
  401.  
  402.     if ((year >= 1620) && (year <= 2000)) {
  403.         i = Math.floor((year - 1620) / 2);
  404.         f = ((year - 1620) / 2) - i;  /* Fractional part of year */
  405.         dt = deltaTtab[i] + ((deltaTtab[i + 1] - deltaTtab[i]) * f);
  406.     } else {
  407.         t = (year - 2000) / 100;
  408.         if (year < 948) {
  409.             dt = 2177 + (497 * t) + (44.1 * t * t);
  410.         } else {
  411.             dt = 102 + (102 * t) + (25.3 * t * t);
  412.             if ((year > 2000) && (year < 2100)) {
  413.                 dt += 0.37 * (year - 2100);
  414.             }
  415.         }
  416.     }
  417.     return dt;
  418. }
  419.  
  420. /*  EQUINOX  --  Determine the Julian Ephemeris Day of an
  421.                  equinox or solstice.  The "which" argument
  422.                  selects the item to be computed:
  423.  
  424.                     0   March equinox
  425.                     1   June solstice
  426.                     2   September equinox
  427.                     3   December solstice
  428.  
  429. */
  430.  
  431. //  Periodic terms to obtain true time
  432.  
  433. var EquinoxpTerms = new Array(
  434.                        485, 324.96,   1934.136,
  435.                        203, 337.23,  32964.467,
  436.                        199, 342.08,     20.186,
  437.                        182,  27.85, 445267.112,
  438.                        156,  73.14,  45036.886,
  439.                        136, 171.52,  22518.443,
  440.                         77, 222.54,  65928.934,
  441.                         74, 296.72,   3034.906,
  442.                         70, 243.58,   9037.513,
  443.                         58, 119.81,  33718.147,
  444.                         52, 297.17,    150.678,
  445.                         50,  21.02,   2281.226,
  446.                         45, 247.54,  29929.562,
  447.                         44, 325.15,  31555.956,
  448.                         29,  60.93,   4443.417,
  449.                         18, 155.12,  67555.328,
  450.                         17, 288.79,   4562.452,
  451.                         16, 198.04,  62894.029,
  452.                         14, 199.76,  31436.921,
  453.                         12,  95.39,  14577.848,
  454.                         12, 287.11,  31931.756,
  455.                         12, 320.81,  34777.259,
  456.                          9, 227.73,   1222.114,
  457.                          8,  15.45,  16859.074
  458.                              );
  459.  
  460. JDE0tab1000 = new Array(
  461.    new Array(1721139.29189, 365242.13740,  0.06134,  0.00111, -0.00071),
  462.    new Array(1721233.25401, 365241.72562, -0.05323,  0.00907,  0.00025),
  463.    new Array(1721325.70455, 365242.49558, -0.11677, -0.00297,  0.00074),
  464.    new Array(1721414.39987, 365242.88257, -0.00769, -0.00933, -0.00006)
  465.                        );
  466.  
  467. JDE0tab2000 = new Array(
  468.    new Array(2451623.80984, 365242.37404,  0.05169, -0.00411, -0.00057),
  469.    new Array(2451716.56767, 365241.62603,  0.00325,  0.00888, -0.00030),
  470.    new Array(2451810.21715, 365242.01767, -0.11575,  0.00337,  0.00078),
  471.    new Array(2451900.05952, 365242.74049, -0.06223, -0.00823,  0.00032)
  472.                        );
  473.  
  474. function equinox(year, which)
  475. {
  476.     var deltaL, i, j, JDE0, JDE, JDE0tab, S, T, W, Y;
  477.  
  478.     /*  Initialise terms for mean equinox and solstices.  We
  479.         have two sets: one for years prior to 1000 and a second
  480.         for subsequent years.  */
  481.  
  482.     if (year < 1000) {
  483.         JDE0tab = JDE0tab1000;
  484.         Y = year / 1000;
  485.     } else {
  486.         JDE0tab = JDE0tab2000;
  487.         Y = (year - 2000) / 1000;
  488.     }
  489.  
  490.     JDE0 =  JDE0tab[which][0] +
  491.            (JDE0tab[which][1] * Y) +
  492.            (JDE0tab[which][2] * Y * Y) +
  493.            (JDE0tab[which][3] * Y * Y * Y) +
  494.            (JDE0tab[which][4] * Y * Y * Y * Y);
  495.  
  496. //document.debug.log.value += "JDE0 = " + JDE0 + "\n";
  497.  
  498.     T = (JDE0 - 2451545.0) / 36525;
  499. //document.debug.log.value += "T = " + T + "\n";
  500.     W = (35999.373 * T) - 2.47;
  501. //document.debug.log.value += "W = " + W + "\n";
  502.     deltaL = 1 + (0.0334 * dcos(W)) + (0.0007 * dcos(2 * W));
  503. //document.debug.log.value += "deltaL = " + deltaL + "\n";
  504.  
  505.     //  Sum the periodic terms for time T
  506.  
  507.     S = 0;
  508.     for (i = j = 0; i < 24; i++) {
  509.         S += EquinoxpTerms[j] * dcos(EquinoxpTerms[j + 1] + (EquinoxpTerms[j + 2] * T));
  510.         j += 3;
  511.     }
  512.  
  513. //document.debug.log.value += "S = " + S + "\n";
  514. //document.debug.log.value += "Corr = " + ((S * 0.00001) / deltaL) + "\n";
  515.  
  516.     JDE = JDE0 + ((S * 0.00001) / deltaL);
  517.  
  518.     return JDE;
  519. }
  520.  
  521. /*  SUNPOS  --  Position of the Sun.  Please see the comments
  522.                 on the return statement at the end of this function
  523.                 which describe the array it returns.  We return
  524.                 intermediate values because they are useful in a
  525.                 variety of other contexts.  */
  526.  
  527. function sunpos(jd)
  528. {
  529.     var T, T2, L0, M, e, C, sunLong, sunAnomaly, sunR,
  530.         Omega, Lambda, epsilon, epsilon0, Alpha, Delta,
  531.         AlphaApp, DeltaApp;
  532.  
  533.     T = (jd - J2000) / JulianCentury;
  534. //document.debug.log.value += "Sunpos.  T = " + T + "\n";
  535.     T2 = T * T;
  536.     L0 = 280.46646 + (36000.76983 * T) + (0.0003032 * T2);
  537. //document.debug.log.value += "L0 = " + L0 + "\n";
  538.     L0 = fixangle(L0);
  539. //document.debug.log.value += "L0 = " + L0 + "\n";
  540.     M = 357.52911 + (35999.05029 * T) + (-0.0001537 * T2);
  541. //document.debug.log.value += "M = " + M + "\n";
  542.     M = fixangle(M);
  543. //document.debug.log.value += "M = " + M + "\n";
  544.     e = 0.016708634 + (-0.000042037 * T) + (-0.0000001267 * T2);
  545. //document.debug.log.value += "e = " + e + "\n";
  546.     C = ((1.914602 + (-0.004817 * T) + (-0.000014 * T2)) * dsin(M)) +
  547.         ((0.019993 - (0.000101 * T)) * dsin(2 * M)) +
  548.         (0.000289 * dsin(3 * M));
  549. //document.debug.log.value += "C = " + C + "\n";
  550.     sunLong = L0 + C;
  551. //document.debug.log.value += "sunLong = " + sunLong + "\n";
  552.     sunAnomaly = M + C;
  553. //document.debug.log.value += "sunAnomaly = " + sunAnomaly + "\n";
  554.     sunR = (1.000001018 * (1 - (e * e))) / (1 + (e * dcos(sunAnomaly)));
  555. //document.debug.log.value += "sunR = " + sunR + "\n";
  556.     Omega = 125.04 - (1934.136 * T);
  557. //document.debug.log.value += "Omega = " + Omega + "\n";
  558.     Lambda = sunLong + (-0.00569) + (-0.00478 * dsin(Omega));
  559. //document.debug.log.value += "Lambda = " + Lambda + "\n";
  560.     epsilon0 = obliqeq(jd);
  561. //document.debug.log.value += "epsilon0 = " + epsilon0 + "\n";
  562.     epsilon = epsilon0 + (0.00256 * dcos(Omega));
  563. //document.debug.log.value += "epsilon = " + epsilon + "\n";
  564.     Alpha = rtd(Math.atan2(dcos(epsilon0) * dsin(sunLong), dcos(sunLong)));
  565. //document.debug.log.value += "Alpha = " + Alpha + "\n";
  566.     Alpha = fixangle(Alpha);
  567. ////document.debug.log.value += "Alpha = " + Alpha + "\n";
  568.     Delta = rtd(Math.asin(dsin(epsilon0) * dsin(sunLong)));
  569. ////document.debug.log.value += "Delta = " + Delta + "\n";
  570.     AlphaApp = rtd(Math.atan2(dcos(epsilon) * dsin(Lambda), dcos(Lambda)));
  571. //document.debug.log.value += "AlphaApp = " + AlphaApp + "\n";
  572.     AlphaApp = fixangle(AlphaApp);
  573. //document.debug.log.value += "AlphaApp = " + AlphaApp + "\n";
  574.     DeltaApp = rtd(Math.asin(dsin(epsilon) * dsin(Lambda)));
  575. //document.debug.log.value += "DeltaApp = " + DeltaApp + "\n";
  576.  
  577.     return new Array(                 //  Angular quantities are expressed in decimal degrees
  578.         L0,                           //  [0] Geometric mean longitude of the Sun
  579.         M,                            //  [1] Mean anomaly of the Sun
  580.         e,                            //  [2] Eccentricity of the Earth's orbit
  581.         C,                            //  [3] Sun's equation of the Centre
  582.         sunLong,                      //  [4] Sun's true longitude
  583.         sunAnomaly,                   //  [5] Sun's true anomaly
  584.         sunR,                         //  [6] Sun's radius vector in AU
  585.         Lambda,                       //  [7] Sun's apparent longitude at true equinox of the date
  586.         Alpha,                        //  [8] Sun's true right ascension
  587.         Delta,                        //  [9] Sun's true declination
  588.         AlphaApp,                     // [10] Sun's apparent right ascension
  589.         DeltaApp                      // [11] Sun's apparent declination
  590.     );
  591. }
  592.  
  593. /*  EQUATIONOFTIME  --  Compute equation of time for a given moment.
  594.                         Returns the equation of time as a fraction of
  595.                         a day.  */
  596.  
  597. function equationOfTime(jd)
  598. {
  599.     var alpha, deltaPsi, E, epsilon, L0, tau
  600.  
  601.     tau = (jd - J2000) / JulianMillennium;
  602. //document.debug.log.value += "equationOfTime.  tau = " + tau + "\n";
  603.     L0 = 280.4664567 + (360007.6982779 * tau) +
  604.          (0.03032028 * tau * tau) +
  605.          ((tau * tau * tau) / 49931) +
  606.          (-((tau * tau * tau * tau) / 15300)) +
  607.          (-((tau * tau * tau * tau * tau) / 2000000));
  608. //document.debug.log.value += "L0 = " + L0 + "\n";
  609.     L0 = fixangle(L0);
  610. //document.debug.log.value += "L0 = " + L0 + "\n";
  611.     alpha = sunpos(jd)[10];
  612. //document.debug.log.value += "alpha = " + alpha + "\n";
  613.     deltaPsi = nutation(jd)[0];
  614. //document.debug.log.value += "deltaPsi = " + deltaPsi + "\n";
  615.     epsilon = obliqeq(jd) + nutation(jd)[1];
  616. //document.debug.log.value += "epsilon = " + epsilon + "\n";
  617.     E = L0 + (-0.0057183) + (-alpha) + (deltaPsi * dcos(epsilon));
  618. //document.debug.log.value += "E = " + E + "\n";
  619.     E = E - 20.0 * (Math.floor(E / 20.0));
  620. //document.debug.log.value += "Efixed = " + E + "\n";
  621.     E = E / (24 * 60);
  622. //document.debug.log.value += "Eday = " + E + "\n";
  623.  
  624.     return E;
  625. }
  626.